import os
import time
import numpy as np
from GV import Path
from common.log import logger


def getNowTime():
    """
        获取当前时间
        """
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(" ", "_")


def getOutPutPath():
    """
        获取当前文件路径
        """
    return Path + "/output/"


def top(filepath):
    with open(filepath, "r") as f:
        line = f.readline()
        process = []
        while line:
            print(line.strip().split())
            if len(line.strip().split()) > 0:
                if line.strip().split()[-1] == "com.mega.map":
                    process.append(float(line.strip().split()[-4]))
            line = f.readline()

    print(np.mean(process))


def is_offline(devices):
    """
    判断设备是否离线
    :param devices:
    :return:
    """
    logger.debug(devices)
    return not os.popen("adb devices").read().__contains__(str(devices))


def adb_root():
    """
    提升权限
    :return:
    """
    os.popen('adb root')
    if os.popen('adb remount').read().__contains__('remount succeeded'):
        logger.debug("提权成功")
        return 1
    else:
        logger.error("提权失败")
        return 0


def strTocode():
    """
    将字符串转换成代码
    :return:
    """
    adb1 = "adb1_代码"
    adb2 = "adb2—代码"
    adb3 = "adb3——代码"

    for i in range(1, 4):
        print(eval(f'adb{i}'))


if __name__ == '__main__':
    strTocode()
    ...
